// pages/tests/index.js
const $http = require('../../request/index');

Page({

  /**
   * 页面的初始数据
   */
  data: {
    examsList: [],

  },
  onLoad: function (options) {
    this.getExamList();
  },
  getExamList() {
    $http.request("GET", `/front/exams`, "").then(res => {
      let { data } = res.data
      let { records } = data;
      this.setData({
        examsList: records
      })
      console.log("data", records)
    })
  },
  onpenIntoExam(event) {
    let { item } = event.currentTarget.dataset
    // 进行拦截 看现在的试卷 是否能达到time的时间 
    let time = new Date(+new Date() + 8 * 3600 * 1000).toJSON().substr(0, 19).replace("T", " ");
    if (item.startTime > time) {
      wx.showToast({
        title: '还未开始',
        icon: 'loading',
        duration: 1500
      })
    } else {
      wx.navigateTo({
        url: `/pages/test-detail/index?id=${item.id}&type=${item.type}`,
      });
    }
    // 读取 点击第几项的值 
    console.log("event", item)

  },

  checkAnswer(event) {

    let { item } = event.currentTarget.dataset

    wx.navigateTo({
      url: `/pages/checkAnswer/index?id=${item.id}`,
    });
  }
})